package com.job.springSea.work0716;

import java.util.Calendar;

/**
 * @author 于春海
 * @version 1.0
 * @since 2022-07-16 16:09:41
 */
public class UseCalendar {
    public static void main(String[] args) {
        //获取当前时间的日历
        Calendar now= Calendar.getInstance();
        System.out.println(now);
        //获取各种字段值

        int year=now.get(Calendar.YEAR);
        int month =now.get(Calendar.MONTH)+1;
        int day=now.get(Calendar.DAY_OF_MONTH);
        System.out.println(year+"-"+month+"-"+day);

        //修改
//        now.set(Calendar.HOUR_OF_DAY, 20);
//        System.out.println(now);

        //在年上面 找历史   之前39年
        //修改月份 之前39个月
//        now.add(Calendar.YEAR,-39);
//        System.out.println(now);
        now.add(Calendar.MONTH,-39);
        System.out.println(now);  // 2019 4

        // 跟日期对象的转换
        //1:用日期时间重置日历
//        Date rightNow=new Date();
//        now.setTime(rightNow);
//        System.out.println(now);
        //2:获取日历表示时间的日期对象
//        Date date=now.getTime();
//        System.out.println(date);
    }
}